﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Outpatient.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_OtpPayWay_code : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpPayRec_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpPayRec_OtpPayWay_PayWayId",
                schema: "Outpatient",
                table: "OtpPayRec");

            migrationBuilder.RenameColumn(
                name: "PayWayCodg",
                schema: "Outpatient",
                table: "OtpPayWay",
                newName: "PayWayCode");

            migrationBuilder.RenameColumn(
                name: "PayWayId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "OtpPayWayId");

            migrationBuilder.RenameColumn(
                name: "OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "OtpOrdRecId");

            migrationBuilder.RenameIndex(
                name: "IX_OtpPayRec_PayWayId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "IX_OtpPayRec_OtpPayWayId");

            migrationBuilder.RenameIndex(
                name: "IX_OtpPayRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "IX_OtpPayRec_OtpOrdRecId");

            migrationBuilder.RenameColumn(
                name: "OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                newName: "OtpOrdRecId");

            migrationBuilder.RenameIndex(
                name: "IX_OtpOrdFeeDetl_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                newName: "IX_OtpOrdFeeDetl_OtpOrdRecId");

            migrationBuilder.AlterColumn<string>(
                name: "Icon",
                schema: "Outpatient",
                table: "OtpPayWay",
                type: "text",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.AddColumn<DateTime>(
                name: "PayValiTime",
                schema: "Outpatient",
                table: "OtpOrdRec",
                type: "timestamp without time zone",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrdRec_OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                column: "OtpOrdRecId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrdRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpPayRec_OtpOrdRec_OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "OtpOrdRecId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrdRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpPayRec_OtpPayWay_OtpPayWayId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "OtpPayWayId",
                principalSchema: "Outpatient",
                principalTable: "OtpPayWay",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrdRec_OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpPayRec_OtpOrdRec_OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpPayRec");

            migrationBuilder.DropForeignKey(
                name: "FK_OtpPayRec_OtpPayWay_OtpPayWayId",
                schema: "Outpatient",
                table: "OtpPayRec");

            migrationBuilder.DropColumn(
                name: "PayValiTime",
                schema: "Outpatient",
                table: "OtpOrdRec");

            migrationBuilder.RenameColumn(
                name: "PayWayCode",
                schema: "Outpatient",
                table: "OtpPayWay",
                newName: "PayWayCodg");

            migrationBuilder.RenameColumn(
                name: "OtpPayWayId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "PayWayId");

            migrationBuilder.RenameColumn(
                name: "OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "OrdInfoId");

            migrationBuilder.RenameIndex(
                name: "IX_OtpPayRec_OtpPayWayId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "IX_OtpPayRec_PayWayId");

            migrationBuilder.RenameIndex(
                name: "IX_OtpPayRec_OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpPayRec",
                newName: "IX_OtpPayRec_OrdInfoId");

            migrationBuilder.RenameColumn(
                name: "OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                newName: "OrdInfoId");

            migrationBuilder.RenameIndex(
                name: "IX_OtpOrdFeeDetl_OtpOrdRecId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                newName: "IX_OtpOrdFeeDetl_OrdInfoId");

            migrationBuilder.AlterColumn<string>(
                name: "Icon",
                schema: "Outpatient",
                table: "OtpPayWay",
                type: "text",
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpOrdFeeDetl_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpOrdFeeDetl",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrdRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpPayRec_OtpOrdRec_OrdInfoId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "OrdInfoId",
                principalSchema: "Outpatient",
                principalTable: "OtpOrdRec",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_OtpPayRec_OtpPayWay_PayWayId",
                schema: "Outpatient",
                table: "OtpPayRec",
                column: "PayWayId",
                principalSchema: "Outpatient",
                principalTable: "OtpPayWay",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
